<template>
  <div style="background: #fff; padding: 40px 0" v-loading="loading">
    <div class="tables">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="广告计划" name="first">
          <div
            class="el-row is-align-middle el-row--flex"
            style="margin-bottom: 20px"
          >
            当前主账号：{{ code }}
          </div>

          <div class="el-row is-align-middle el-row--flex">
            <div class="form-wrapper" style="margin-right: 10px; width: 300px">
              <el-input
                v-model="seachid"
                placeholder="广告计划编号"
                size="small"
                class="select-wrapper"
                filterable
                @change="chuanid"
                style="margin-right: 15px"
              >
              </el-input>
            </div>
            <div class="form-wrapper" style="margin-right: 10px">
              <!-- <span class="filter-label">时间：</span> -->
              <el-date-picker
                v-model="seachtime"
                size="small"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                align="right"
                :clearable="false"
                @change="fenzutime"
              >
              </el-date-picker>
            </div>

            <div class="form-wrapper">
              <el-button
                data-v-6a3b3888=""
                class="el-button--primary el-button"
                style="float: left"
                size="small"
                @click="chaxun"
                ><i class="el-icon-search"></i
                ><span> 查询搜索 </span></el-button
              >
            </div>
            <div class="form-wrapper" style="width: 650px">
              <span style="margin-left: 20px; color: red"
                >更新时间：{{ ggnewtime }}</span
              >
            </div>
            <el-dropdown :hide-on-click="false" class="right">
              <el-button
                type="primary"
                icon="el-icon-s-operation"
                class="zd"
                style="
                  display: flex;
                  align-items: center;
                  justify-content: center;
                "
                >自定义列表</el-button
              >
              <el-dropdown-menu slot="dropdown">
                <el-scrollbar style="height: 60vh" width="200px">
                  <el-checkbox-group v-model="check">
                    <el-dropdown-item
                      v-for="(item, index) in checkList"
                      :key="index"
                      ><el-checkbox :label="item" :key="item"></el-checkbox>
                    </el-dropdown-item>
                  </el-checkbox-group>
                </el-scrollbar>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <el-table
            :data="
              ggList.slice(
                (ggcurrentPage - 1) * ggpageSize,
                ggcurrentPage * ggpageSize
              )
            "
            border
            stripe
            :header-cell-style="{
              'text-align': 'center',
              background: 'rgb(84, 92, 100)',
              color: '#fff',
            }"
            style="width: 100%; margin-top: 20px"
          >
            <el-table-column
              prop="campaign_name"
              label="广告计划名称"
              width="180"
              fixed
            >
            </el-table-column>
            <el-table-column
              prop="campaign_id"
              label="广告计划 ID"
              width="180"
              fixed
            >
            </el-table-column>
            <!-- <el-table-column prop="charge" label="花费（元）" width="120"> </el-table-column>
            <el-table-column prop="aclick" label="素材曝光数"  width="120">
            </el-table-column>
            <el-table-column prop="action_cost" label="平均行为单价（元）" width="120"> </el-table-column>
            <el-table-column prop="action_ratio" label="行为率" width="120"> </el-table-column>
            <el-table-column prop="bclick" label="行为数" width="120"> </el-table-column>
            <el-table-column prop="conversion_num" label="转化数" width="120"> </el-table-column>
            <el-table-column prop="conversion_num_cost" label="转化成本" width="120"> </el-table-column>
            <el-table-column prop="conversion_ratio" label="转化率" width="120"> </el-table-column>
            <el-table-column prop="event_order_paid" label="付款成功数" width="120"> </el-table-column>
            <el-table-column prop="event_order_paid_purchase_amount" label="付款成功金额" width="120"> </el-table-column>
            <el-table-column prop="event_pay" label="付费次数" width="120"> </el-table-column>
            <el-table-column prop="event_pay_purchase_amount" label="付费金额" width="120"> </el-table-column>
            <el-table-column prop="event_pay_roi" label="ROI" width="120"> </el-table-column>
            <el-table-column prop="impression_1k_cost" label="平均千次曝光花费（元）" width="120"> </el-table-column>
            <el-table-column prop="photo_click" label="封面点击数" width="120"> </el-table-column>
            <el-table-column prop="photo_click_cost" label="平均点击单价（元）" width="120"> </el-table-column>
            <el-table-column prop="photo_click_ratio" label="封面点击率" width="120"> </el-table-column>
            <el-table-column prop="play_3s_ratio" label="3s 播放率" width="120"> </el-table-column>
            <el-table-column prop="show" label="封面曝光数" width="120"> </el-table-column> -->
            <el-table-column
              v-for="item in lists"
              :key="Math.random()"
              :prop="item.prop"
              :label="item.label"
              v-if="item.ispass"
            >
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="end" style="margin-top: 20px">
            <el-pagination
              background
              @current-change="gghandleCurrentChange"
              :current-page="ggcurrentPage"
              :page-size="ggpageSize"
              layout=" prev, pager, next"
              :total="ggtotal"
            >
            </el-pagination>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="订单明细" name="second">
          <ol class="daochu">
            <li>成功订单：{{success.goods_quantity}}</li>
            <li>成功金额：{{success.order_amount}}（￥）</li>
            <li>失败订单：{{lose.goods_quantity}}</li>
            <li>失败金额：{{lose.order_amount}}（￥）</li>
          </ol>
          <div
            class="watchtime is-align-middle el-row--flex"
            style="margin-bottom: 20px"
          >
            <div class="form-wrapper" style="margin-right: 10px">
              <el-input
                v-model="dindanid"
                placeholder="订单编号"
                class="select-wrapper"
                filterable
                @change="pushid"
                style="margin-right: 15px"
              >
              </el-input>
            </div>
            <el-date-picker
              v-model="seachtime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="shijian"
            >
            </el-date-picker>
            <el-select v-model="typeval" filterable placeholder="请选择" clearable @change="typechange" style="margin-left:10px;">
                <el-option
                  v-for="item in typelist"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="seachlist"
              style="margin-left: 10px"
              >查询</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-download"
              @click="outlist"
              style="margin-left: 10px"
              >导出订单</el-button
            >
          </div>
          <el-table
            :data="
              orderList.slice(
                (ddcurrentPage - 1) * ddpageSize,
                ddcurrentPage * ddpageSize
              )
            "
            border
            :header-cell-style="{
              'text-align': 'center',
              background: 'rgb(84, 92, 100)',
              color: '#fff',
            }"
            style="width: 100%"
          >
            <el-table-column prop="order_id" label="订单编号" align="center">
            </el-table-column>
            <el-table-column prop="order_type" label="订单类型" align="center">
            </el-table-column>
            <el-table-column prop="aadv_id" label="广告组id" align="center">
            </el-table-column>
            <el-table-column prop="ad_id" label="广告计划id" align="center">
            </el-table-column>
            <el-table-column prop="goods_name" label="商品信息" align="center">
            </el-table-column>
            <el-table-column
              prop="goods_quantity"
              sortable
              label="支付订单数量"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="order_amount"
              sortable
              label="实际支付金额"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="order_time"
              sortable
              label="支付时间"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="order_status"
              sortable
              label="订单状态"
              align="center"
            >
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="end" style="margin-top: 20px">
            <el-pagination
              background
              @current-change="ddhandleCurrentChange"
              :current-page="ddcurrentPage"
              :page-size="ddpageSize"
              layout=" prev, pager, next"
              :total="ddtotal"
            >
            </el-pagination>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import Sortable from "sortablejs";
export default {
  data() {
    return {
      code: "",
      gid:"",
      type_id:'',
      order_sta:'',
      typeval:'',
      typelist:[],
      orderList: [],
      ggList: [],
      ddcurrentPage: 1,
      ddpageSize: 10,
      ddtotal: 0,
      ggcurrentPage: 1,
      ggpageSize: 10,
      ggtotal: 0,
      stat_time: "",
      end_time: "",
      stat: "",
      end: "",
      seachtime: "",
      loading: false,
      activeName: "first",
      seachid: "",
      dindanid: "",
      ggnewtime: "",
      check: [
        "花费（元）",
        "素材曝光数",
        "平均行为单价（元）",
        "行为率",
        "行为数",
        "转化数",
        "转化率",
        "ROI",
      ],
      checkList: [
        "花费（元）",
        "素材曝光数",
        "平均行为单价（元）",
        "行为率",
        "行为数",
        "转化数",
        "转化成本",
        "转化率",
        "付款成功数",
        "付款成功金额",
        "付费次数",
        "付费金额",
        "ROI",
        "平均千次曝光花费（元）",
        "封面点击数",
        "平均点击单价（元）",
        "封面点击率",
        "3s 播放率",
        "封面曝光数",
      ],
      col: [
        {
          label: "花费（元）",
          prop: "charge",
          ispass: true,
        },
        {
          label: "素材曝光数",
          prop: "aclick",
          ispass: true,
        },
        {
          label: "平均行为单价（元）",
          prop: "action_cost",
          ispass: true,
        },
        {
          label: "行为率",
          prop: "action_ratio",
          ispass: true,
        },
        {
          label: "行为数",
          prop: "bclick",
          ispass: true,
        },
        {
          label: "转化数",
          prop: "conversion_num",
          ispass: true,
        },
        {
          label: "转化率",
          prop: "conversion_ratio",
          ispass: true,
        },
        {
          label: "ROI",
          prop: "event_pay_roi",
          ispass: true,
        },
        {
          label: "付费次数",
          prop: "event_pay",
          ispass: false,
        },
        {
          label: "付费金额",
          prop: "event_pay_purchase_amount",
          ispass: false,
        },
        {
          label: "转化成本",
          prop: "conversion_num_cost",
          ispass: false,
        },
        {
          label: "付款成功数",
          prop: "event_order_paid",
          ispass: false,
        },
        {
          label: "付款成功金额",
          prop: "event_order_paid_purchase_amount",
          ispass: false,
        },
        {
          label: "平均千次曝光花费（元）",
          prop: "impression_1k_cost",
          ispass: false,
        },
        {
          label: "封面点击数",
          prop: "photo_click",
          ispass: false,
        },
        {
          label: "平均点击单价（元）",
          prop: "photo_click_cost",
          ispass: false,
        },
        {
          label: "封面点击率",
          prop: "photo_click_ratio",
          ispass: false,
        },
        {
          label: "3s 播放率",
          prop: "play_3s_ratio",
          ispass: false,
        },
        {
          label: "封面曝光数",
          prop: "show",
          ispass: false,
        },
      ],
      dropCol: [
        {
          label: "花费（元）",
          prop: "charge",
        },
        {
          label: "素材曝光数",
          prop: "aclick",
        },
        {
          label: "平均行为单价（元）",
          prop: "action_cost",
        },
        {
          label: "行为率",
          prop: "action_ratio",
        },
        {
          label: "行为数",
          prop: "bclick",
        },
        {
          label: "转化数",
          prop: "conversion_num",
        },
        {
          label: "转化率",
          prop: "conversion_ratio",
        },
        {
          label: "ROI",
          prop: "event_pay_roi",
        },
        {
          label: "付费次数",
          prop: "event_pay",
        },
        {
          label: "付费金额",
          prop: "event_pay_purchase_amount",
        },
        {
          label: "转化成本",
          prop: "conversion_num_cost",
        },
        {
          label: "付款成功数",
          prop: "event_order_paid",
        },
        {
          label: "付款成功金额",
          prop: "event_order_paid_purchase_amount",
        },
        {
          label: "平均千次曝光花费（元）",
          prop: "impression_1k_cost",
        },
        {
          label: "封面点击数",
          prop: "photo_click",
        },
        {
          label: "平均点击单价（元）",
          prop: "photo_click_cost",
        },
        {
          label: "封面点击率",
          prop: "photo_click_ratio",
        },
        {
          label: "3s 播放率",
          prop: "play_3s_ratio",
        },
        {
          label: "封面曝光数",
          prop: "show",
        },
      ],
      lists: [
        {
          label: "花费（元）",
          prop: "charge",
          ispass: true,
        },
        {
          label: "素材曝光数",
          prop: "aclick",
          ispass: true,
        },
        {
          label: "平均行为单价（元）",
          prop: "action_cost",
          ispass: true,
        },
        {
          label: "行为率",
          prop: "action_ratio",
          ispass: true,
        },
        {
          label: "行为数",
          prop: "bclick",
          ispass: true,
        },
        {
          label: "转化数",
          prop: "conversion_num",
          ispass: true,
        },
        {
          label: "转化率",
          prop: "conversion_ratio",
          ispass: true,
        },
        {
          label: "ROI",
          prop: "event_pay_roi",
          ispass: true,
        },
      ],
      lose:{
        goods_quantity:'',
        order_amount:''
      },
      success:{
        goods_quantity:"",
        order_amount:''
      }
      
    };
  },
  watch: {
    check(newVal) {
      if (newVal) {
        var arr = this.checkList.filter((i) => newVal.indexOf(i) < 0); //未选中
        this.lists = [];
        this.col.map((i) => {
          if (arr.indexOf(i.label) !== -1) {
            i.ispass = false;
          } else {
            i.ispass = true;
            if (i.ispass == true) {
              this.lists.push(i);
            }
          }
        });
        const newtr = document.querySelector(".el-table__header-wrapper tr");
        this.sortable = Sortable.create(newtr, {
          animation: 180,
          delay: 0,
          onEnd: (evt) => {
            if (evt.newIndex > 1) {
              const oldItem = this.lists[evt.oldIndex - 2];
              this.lists.splice(evt.oldIndex - 2, 1);
              this.lists.splice(evt.newIndex - 2, 0, oldItem);
            }
          },
        });
      }
    },
  },
  mounted() {
    this.code = this.$route.query.code;
    this.gid = this.$route.query.gid
    this.type_id = this.$route.query.type
    console.log(this.type_id,123);
    if(this.type_id == "拼多多"){
      this.typelist = [{
          value:-1,
          label:"未支付"
        },
        {
          value:0,
          label:"已支付"
        },
        {
          value:1,
          label:"已成团"
        },
        {
          value:2,
          label:"确认收货"
        },
        {
          value:3,
          label:"审核成功"
        },
        {
          value:4,
          label:"审核失败（不可提现）"
        },
        {
          value:5,
          label:"已经结算"
        },
        {
          value:6,
          label:"非多多进宝商品"
        },]
    }else if(this.type_id == "淘宝"){
      this.typelist = [
        {
          value:3,
          label:"订单结算"
        },
        {
          value:12,
          label:"订单付款"
        },
        {
          value:13,
          label:"订单失效"
        },
        {
          value:14,
          label:"订单成功"
        }
      ]
    }else if(this.type_id == "京东"){
      this.typelist = [
        {
          value:15,
          label:"待付款"
        },
        {
          value:16,
          label:"已付款"
        },
        {
          value:17,
          label:"已完成"
        }
      ]
    }
    this.times();
    this.guangao();
    this.columnDrop();
    // this.seachtime = [this.stat_time, this.end_time]
  },
  methods: {
    // 方法
    columnDrop() {
      const wrapperTr = document.querySelector(".el-table__header-wrapper tr");
      this.sortable = Sortable.create(wrapperTr, {
        animation: 180,
        delay: 0,
        onEnd: (evt) => {
          if (evt.newIndex > 1) {
            const oldItem = this.lists[evt.oldIndex - 2];
            this.lists.splice(evt.oldIndex - 2, 1);
            this.lists.splice(evt.newIndex - 2, 0, oldItem);
          }
        },
      });
    },
    chuanid(seachid) {
      this.seachid = seachid;
    },
    pushid(dindanid) {
      this.pushid = dindanid;
    },
    ddhandleCurrentChange(val) {
      //   console.log(val);
      this.ddcurrentPage = val;
    },
    gghandleCurrentChange(val) {
      //   console.log(val);
      this.ggcurrentPage = val;
    },
    times() {
      
      // this.loading = true;
      let nowyear = new Date().getFullYear();
      //月份是从0月开始获取的，所以要+1;
      let nowmonth = new Date().getMonth() + 1;
      //日
      let nowday = new Date().getDate();
      if (nowmonth <= 9) {
        let months = "0" + nowmonth;
        let time = nowyear + "-" + months + "-" + nowday;
        this.stat_time = time;
        this.end_time = time;
        this.seachtime = [this.stat_time, this.end_time];
        if (nowday <= 9) {
          let days = "0" + nowday;
          let time = nowyear + "-" + months + "-" + days;
          this.stat_time = time;
          this.end_time = time;
          this.seachtime = [this.stat_time, this.end_time];
        } else {
          let time = nowyear + "-" + months + "-" + nowday;
          this.stat_time = time;
          this.end_time = time;
          this.seachtime = [this.stat_time, this.end_time];
        }
      } else {
        let time = nowyear + "-" + nowmonth + "-" + nowday;
        this.stat_time = time;
        this.end_time = time;
        this.seachtime = [this.stat_time, this.end_time];
        if (nowday <= 9) {
          let days = "0" + nowday;
          let time = nowyear + "-" + nowmonth + "-" + days;
          this.stat_time = time;
          this.end_time = time;
          this.seachtime = [this.stat_time, this.end_time];
        } else {
          let time = nowyear + "-" + nowmonth + "-" + nowday;
          this.stat_time = time;
          this.end_time = time;
          this.seachtime = [this.stat_time, this.end_time];
        }
      }

      this.$axios
        .get("/api/order/order_tb_find", {
          code: this.code,
          stat: this.stat_time + " 00:00:00",
          end: this.end_time + " 23:59:59",
        })
        .then((res) => {
          console.log('0')
          for (var i = 0; i <= res.data.data.data.length; i++) {
            if (res.data.data.data[i].order_type == 1) {
                res.data.data.data[i].order_type = "京东";
                if (res.data.data.data[i].order_status == 15) {
                res.data.data.data[i].order_status = "待付款";
                }else if (res.data.data.data[i].order_status == 16) {
                  res.data.data.data[i].order_status = "已付款";
                } else if (res.data.data.data[i].order_status == 17) {
                  res.data.data.data[i].order_status = "已完成";
                } else {
                  res.data.data.data[i].order_status = "无效订单";
                }
              } else if (res.data.data.data[i].order_type == 2) {
                res.data.data.data[i].order_type = "淘宝";
                if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "订单结算";
                }else if (res.data.data.data[i].order_status == 12) {
                  res.data.data.data[i].order_status = "订单付款";
                } else if (res.data.data.data[i].order_status == 13) {
                  res.data.data.data[i].order_status = "订单失效";
                } else if (res.data.data.data[i].order_status == 14) {
                  res.data.data.data[i].order_status = "订单成功";
                }
            } else if (res.data.data.data[i].order_type == 3) {
              res.data.data.data[i].order_type = "拼多多";
              if (res.data.data.data[i].order_status == -1) {
                res.data.data.data[i].order_status = "未支付";
              } else if (res.data.data.data[i].order_status == 0) {
                res.data.data.data[i].order_status = "已支付";
              } else if (res.data.data.data[i].order_status == 1) {
                res.data.data.data[i].order_status = "已成团";
              } else if (res.data.data.data[i].order_status == 2) {
                res.data.data.data[i].order_status = "确认收货";
              } else if (res.data.data.data[i].order_status == 3) {
                res.data.data.data[i].order_status = "审核成功";
              } else if (res.data.data.data[i].order_status == 4) {
                res.data.data.data[i].order_status = "审核失败（不可提现）";
              } else if (res.data.data.data[i].order_status == 5) {
                res.data.data.data[i].order_status = "已经结算";
              } else if (res.data.data.data[i].order_status == 8) {
                res.data.data.data[i].order_status = "非多多进宝商品";
              }
            }

            this.loading = false;
            this.orderList = res.data.data.data;
            this.ddtotal = this.orderList.length;
            this.lose.goods_quantity = res.data.data.lose.goods_quantity
            this.lose.order_amount = res.data.data.lose.order_amount
            this.success.goods_quantity = res.data.data.success.goods_quantity
            this.success.order_amount = res.data.data.success.order_amount
          }
        })
        .catch((e) => {});
    },
    guangao() {
      // this.loading = true;
      let nowyear = new Date().getFullYear();
      //月份是从0月开始获取的，所以要+1;
      let nowmonth = new Date().getMonth() + 1;
      //日
      let nowday = new Date().getDate();
      if (nowmonth <= 9) {
        let months = "0" + nowmonth;
        let time = nowyear + "-" + months + "-" + nowday;
        this.stat = time;
        this.end = time;
        this.seachtime = [this.stat, this.end];
        if (nowday <= 9) {
          let days = "0" + nowday;
          let time = nowyear + "-" + months + "-" + days;
          this.stat = time;
          this.end = time;
          this.seachtime = [this.stat, this.end];
        } else {
          let time = nowyear + "-" + months + "-" + nowday;
          this.stat = time;
          this.end = time;
          this.seachtime = [this.stat, this.end];
        }
      } else {
        let time = nowyear + "-" + nowmonth + "-" + nowday;
        this.stat = time;
        this.end = time;
        this.seachtime = [this.stat, this.end];
        if (nowday <= 9) {
          let days = "0" + nowday;
          let time = nowyear + "-" + nowmonth + "-" + days;
          this.stat = time;
          this.end = time;
          this.seachtime = [this.stat, this.end];
        } else {
          let time = nowyear + "-" + nowmonth + "-" + nowday;
          this.stat = time;
          this.end = time;
          this.seachtime = [this.stat, this.end];
        }
      }
      this.$axios
        .get("/api/account/campaign_cost", {
          account_id: this.code,
          stat: this.stat,
          end: this.end,
        })
        .then((res) => {
          this.ggList = res.data.data.data;
          this.ggtotal = this.ggList.length;
          this.ggnewtime = res.data.data.data[0].update_time;
        });
    },
    shijian(seachtime) {
      this.stat_time = seachtime[0];
      this.end_time = seachtime[1];
      console.log("开始时间:", this.stat_time, "结束时间:", this.end_time);
    },
    fenzutime(seachtime) {
      console.log(seachtime);
      this.stat = seachtime[0];
      this.end = seachtime[1];
      console.log("开始时间:", this.stat, "结束时间:", this.end);
    },
    typechange(val){
      this.order_sta = val
    },
    seachlist() {
      // this.loading = true;
      if (this.dindanid == "") {
        if(this.order_sta == ""){
          this.$axios
          .get("/api/order/order_tb_find", {
            code: this.code,
            stat: this.stat_time + " 00:00:00",
            end: this.end_time + " 23:59:59",
          })
          .then((res) => {
            // console.log(res.data.data.data,"为空")
            console.log('1')
            if(res.data.data.data.length != 0){
              for (var i = 0; i <= res.data.data.data.length; i++) {
             if (res.data.data.data[i].order_type == 1) {
                res.data.data.data[i].order_type = "京东";
                if (res.data.data.data[i].order_status == 15) {
                res.data.data.data[i].order_status = "待付款";
                }else if (res.data.data.data[i].order_status == 16) {
                  res.data.data.data[i].order_status = "已付款";
                } else if (res.data.data.data[i].order_status == 17) {
                  res.data.data.data[i].order_status = "已完成";
                } else {
                  res.data.data.data[i].order_status = "无效订单";
                }
              } else if (res.data.data.data[i].order_type == 2) {
                res.data.data.data[i].order_type = "淘宝";
                if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "订单结算";
                }else if (res.data.data.data[i].order_status == 12) {
                  res.data.data.data[i].order_status = "订单付款";
                } else if (res.data.data.data[i].order_status == 13) {
                  res.data.data.data[i].order_status = "订单失效";
                } else if (res.data.data.data[i].order_status == 14) {
                  res.data.data.data[i].order_status = "订单成功";
                }
              } else if (res.data.data.data[i].order_type == 3) {
                res.data.data.data[i].order_type = "拼多多";
                if (res.data.data.data[i].order_status == -1) {
                  res.data.data.data[i].order_status = "未支付";
                } else if (res.data.data.data[i].order_status == 0) {
                  res.data.data.data[i].order_status = "已支付";
                } else if (res.data.data.data[i].order_status == 1) {
                  res.data.data.data[i].order_status = "已成团";
                } else if (res.data.data.data[i].order_status == 2) {
                  res.data.data.data[i].order_status = "确认收货";
                } else if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "审核成功";
                } else if (res.data.data.data[i].order_status == 4) {
                  res.data.data.data[i].order_status = "审核失败（不可提现）";
                } else if (res.data.data.data[i].order_status == 5) {
                  res.data.data.data[i].order_status = "已经结算";
                } else if (res.data.data.data[i].order_status == 8) {
                  res.data.data.data[i].order_status = "非多多进宝商品";
                }
              }
              this.loading = false;
              this.orderList = res.data.data.data;
              this.ddtotal = this.orderList.length;
              this.lose.goods_quantity = res.data.data.lose.goods_quantity
              this.lose.order_amount = res.data.data.lose.order_amount
              this.success.goods_quantity = res.data.data.success.goods_quantity
              this.success.order_amount = res.data.data.success.order_amount
            }
            
              
            }else{
              console.log("为空")
              this.loading = false;
              this.orderList = [];
              this.ddtotal = this.orderList.length;
            }
          })
          .catch((e) => {});
        }else{
          this.$axios
          .get("/api/order/order_tb_find", {
            code: this.code,
            stat: this.stat_time + " 00:00:00",
            end: this.end_time + " 23:59:59",
            order_status:this.order_status,
          })
          .then((res) => {
            console.log('2')
           if(res.data.data.data.length != 0){
             for (var i = 0; i <= res.data.data.data.length; i++) {
            if (res.data.data.data[i].order_type == 1) {
                res.data.data.data[i].order_type = "京东";
                if (res.data.data.data[i].order_status == 15) {
                res.data.data.data[i].order_status = "待付款";
                }else if (res.data.data.data[i].order_status == 16) {
                  res.data.data.data[i].order_status = "已付款";
                } else if (res.data.data.data[i].order_status == 17) {
                  res.data.data.data[i].order_status = "已完成";
                } else {
                  res.data.data.data[i].order_status = "无效订单";
                }
              } else if (res.data.data.data[i].order_type == 2) {
                res.data.data.data[i].order_type = "淘宝";
                if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "订单结算";
                }else if (res.data.data.data[i].order_status == 12) {
                  res.data.data.data[i].order_status = "订单付款";
                } else if (res.data.data.data[i].order_status == 13) {
                  res.data.data.data[i].order_status = "订单失效";
                } else if (res.data.data.data[i].order_status == 14) {
                  res.data.data.data[i].order_status = "订单成功";
                }
              } else if (res.data.data.data[i].order_type == 3) {
                res.data.data.data[i].order_type = "拼多多";
                if (res.data.data.data[i].order_status == -1) {
                  res.data.data.data[i].order_status = "未支付";
                } else if (res.data.data.data[i].order_status == 0) {
                  res.data.data.data[i].order_status = "已支付";
                } else if (res.data.data.data[i].order_status == 1) {
                  res.data.data.data[i].order_status = "已成团";
                } else if (res.data.data.data[i].order_status == 2) {
                  res.data.data.data[i].order_status = "确认收货";
                } else if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "审核成功";
                } else if (res.data.data.data[i].order_status == 4) {
                  res.data.data.data[i].order_status = "审核失败（不可提现）";
                } else if (res.data.data.data[i].order_status == 5) {
                  res.data.data.data[i].order_status = "已经结算";
                } else if (res.data.data.data[i].order_status == 8) {
                  res.data.data.data[i].order_status = "非多多进宝商品";
                }
              }

              this.loading = false;
              this.orderList = res.data.data.data;
              this.ddtotal = this.orderList.length;
            this.lose.goods_quantity = res.data.data.lose.goods_quantity
            this.lose.order_amount = res.data.data.lose.order_amount
            this.success.goods_quantity = res.data.data.success.goods_quantity
            this.success.order_amount = res.data.data.success.order_amount
            }
           }else{
              this.loading = false;
              this.orderList = [];
              this.ddtotal = this.orderList.length;
            }
          })
          .catch((e) => {});
        }
      } else {
       if(this.order_sta == ""){
         this.$axios
          .get("/api/order/order_tb_find", {
            code: this.code,
            stat: this.stat_time + " 00:00:00",
            end: this.end_time + " 23:59:59",
            order_id: this.dindanid,
          })
          .then((res) => {
            console.log('3')
            if(res.data.data.data.length != 0){
              for (var i = 0; i <= res.data.data.data.length; i++) {
              if (res.data.data.data[i].order_type == 1) {
                res.data.data.data[i].order_type = "京东";
                if (res.data.data.data[i].order_status == 15) {
                res.data.data.data[i].order_status = "待付款";
                }else if (res.data.data.data[i].order_status == 16) {
                  res.data.data.data[i].order_status = "已付款";
                } else if (res.data.data.data[i].order_status == 17) {
                  res.data.data.data[i].order_status = "已完成";
                } else {
                  res.data.data.data[i].order_status = "无效订单";
                }
              } else if (res.data.data.data[i].order_type == 2) {
                res.data.data.data[i].order_type = "淘宝";
                if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "订单结算";
                }else if (res.data.data.data[i].order_status == 12) {
                  res.data.data.data[i].order_status = "订单付款";
                } else if (res.data.data.data[i].order_status == 13) {
                  res.data.data.data[i].order_status = "订单失效";
                } else if (res.data.data.data[i].order_status == 14) {
                  res.data.data.data[i].order_status = "订单成功";
                }
              } else if (res.data.data.data[i].order_type == 3) {
                res.data.data.data[i].order_type = "拼多多";
                if (res.data.data.data[i].order_status == -1) {
                  res.data.data.data[i].order_status = "未支付";
                } else if (res.data.data.data[i].order_status == 0) {
                  res.data.data.data[i].order_status = "已支付";
                } else if (res.data.data.data[i].order_status == 1) {
                  res.data.data.data[i].order_status = "已成团";
                } else if (res.data.data.data[i].order_status == 2) {
                  res.data.data.data[i].order_status = "确认收货";
                } else if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "审核成功";
                } else if (res.data.data.data[i].order_status == 4) {
                  res.data.data.data[i].order_status = "审核失败（不可提现）";
                } else if (res.data.data.data[i].order_status == 5) {
                  res.data.data.data[i].order_status = "已经结算";
                } else if (res.data.data.data[i].order_status == 8) {
                  res.data.data.data[i].order_status = "非多多进宝商品";
                }
              }
              this.loading = false;
              this.orderList = res.data.data.data;
              this.ddtotal = this.orderList.length;
              this.lose.goods_quantity = res.data.data.lose.goods_quantity
              this.lose.order_amount = res.data.data.lose.order_amount
              this.success.goods_quantity = res.data.data.success.goods_quantity
              this.success.order_amount = res.data.data.success.order_amount
            }
            }else{
              this.loading = false;
              this.orderList = [];
              this.ddtotal = this.orderList.length;
            }
          })
          .catch((e) => {});
       }else{
         this.$axios
          .get("/api/order/order_tb_find", {
            code: this.code,
            stat: this.stat_time + " 00:00:00",
            end: this.end_time + " 23:59:59",
            order_id: this.dindanid,
            order_status:this.order_status,
          })
          .then((res) => {
            console.log('4')
           if(res.data.data.data.length != 0){
             for (var i = 0; i <= res.data.data.data.length; i++) {
              if (res.data.data.data[i].order_type == 1) {
                res.data.data.data[i].order_type = "京东";
                if (res.data.data.data[i].order_status == 15) {
                res.data.data.data[i].order_status = "待付款";
                }else if (res.data.data.data[i].order_status == 16) {
                  res.data.data.data[i].order_status = "已付款";
                } else if (res.data.data.data[i].order_status == 17) {
                  res.data.data.data[i].order_status = "已完成";
                } else {
                  res.data.data.data[i].order_status = "无效订单";
                }
              } else if (res.data.data.data[i].order_type == 2) {
                res.data.data.data[i].order_type = "淘宝";
                if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "订单结算";
                }else if (res.data.data.data[i].order_status == 12) {
                  res.data.data.data[i].order_status = "订单付款";
                } else if (res.data.data.data[i].order_status == 13) {
                  res.data.data.data[i].order_status = "订单失效";
                } else if (res.data.data.data[i].order_status == 14) {
                  res.data.data.data[i].order_status = "订单成功";
                }
              } else if (res.data.data.data[i].order_type == 3) {
                res.data.data.data[i].order_type = "拼多多";
                if (res.data.data.data[i].order_status == -1) {
                  res.data.data.data[i].order_status = "未支付";
                } else if (res.data.data.data[i].order_status == 0) {
                  res.data.data.data[i].order_status = "已支付";
                } else if (res.data.data.data[i].order_status == 1) {
                  res.data.data.data[i].order_status = "已成团";
                } else if (res.data.data.data[i].order_status == 2) {
                  res.data.data.data[i].order_status = "确认收货";
                } else if (res.data.data.data[i].order_status == 3) {
                  res.data.data.data[i].order_status = "审核成功";
                } else if (res.data.data.data[i].order_status == 4) {
                  res.data.data.data[i].order_status = "审核失败（不可提现）";
                } else if (res.data.data.data[i].order_status == 5) {
                  res.data.data.data[i].order_status = "已经结算";
                } else if (res.data.data.data[i].order_status == 8) {
                  res.data.data.data[i].order_status = "非多多进宝商品";
                }
              }

              this.loading = false;
              this.orderList = res.data.data.data;
              this.ddtotal = this.orderList.length;
            this.lose.goods_quantity = res.data.data.lose.goods_quantity
            this.lose.order_amount = res.data.data.lose.order_amount
            this.success.goods_quantity = res.data.data.success.goods_quantity
            this.success.order_amount = res.data.data.success.order_amount
            }
           }else{
              this.loading = false;
              this.orderList = [];
              this.ddtotal = this.orderList.length;
            }
          })
          .catch((e) => {});
       }
      }
    },
    chaxun() {
      if (this.seachid == "") {
        this.$axios
          .get("/api/account/campaign_cost", {
            account_id: this.code,
            stat: this.stat,
            end: this.end,
          })
          .then((res) => {
            this.ggList = res.data.data.data;
            this.ggtotal = this.ggList.length;
            this.ggnewtime = res.data.data.data[0].update_time;
          })
          .catch((e) => {
            console.log(e, 888);
          });
      } else {
        this.$axios
          .get("/api/account/campaign_cost", {
            account_id: this.code,
            ad_id: this.seachid,
            stat: this.stat,
            end: this.end,
          })
          .then((res) => {
            this.ggList = res.data.data.data;
            this.ggtotal = this.ggList.length;
            this.ggnewtime = res.data.data.data[0].update_time;
          })
          .catch((e) => {
            console.log(e, 888);
          });
      }
    },
    outlist(){
      this.$axios
          .exportDetailOrder("/api/order/export", {
            gid: this.gid,
            stat: this.stat_time + " 00:00:00",
            end: this.end_time + " 23:59:59",
          })
          .then((res) => {
             this.downloadCallback(res, '订单明细.xlsx');
          })
          .catch((e) => {});
    },
    downloadCallback(res, fileName){
        const content = res.data;
        const blob = new Blob([content]);
        if ("download" in document.createElement("a")) {
          // 非IE下载
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          // IE10+下载
          navigator.msSaveBlob(blob, fileName);
        }
      },
  },
};
</script>
<style>
.tables {
  width: 98%;
  margin: 0 auto;
}
.right {
  width: 100%;
  height: 40px;
  display: flex !important;
  align-content: center;
  justify-content: flex-end;
  margin-bottom: 10px;
  float: right;
}
.daochu {
  width: 100%;
  display: flex;
  align-content: center;
  justify-content: space-between;
  margin-bottom: 20px;
  list-style-type: none;
}
.daochu li{
  font-size: 22px;
    font-family: Source Han Sans CN-Bold, Source Han Sans CN;
    font-weight: bold;
}
</style>

